import Vue from "vue";
import VueRouter from "vue-router";
import Home from "@/views/home.vue";
import Login from "@/views/login.vue";
import Reg from "@/views/reg.vue";

import List from "@/views/list.vue";
import Search from "@/views/search.vue";

import cart from "@/views/cart.vue";
import index from "@/views/index.vue";
import mytaobao from "@/views/mytaobao.vue";
import orders from "@/views/orders.vue";
import listdetailed from "@/views/listdetailed.vue"; //列表详细页

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch((err) => err);
};

const routes = [
	{
		path: "/",
		redirect: "/home",
	},
	{
		path: "/home",
		name: "home",
		component: Home,
		meta: {
			//元信息
			permission: true,
		},
		redirect: "/home/index",
		children: [
			{
				path: "cart",
				name: "cart",
				component: cart,
				meta: {
					//元信息
					permission: true,
				},
			},
			{
				path: "/home/index",
				name: "index",
				component: index,
				meta: {
					//元信息
					permission: true,
				},
			},
			{
				path: "/home/mytaobao",
				name: "mytaobao",
				component: mytaobao,
				meta: {
					//元信息
					permission: true,
				},
			},
			{
				path: "/home/orders",
				name: "orders",
				component: orders,
				meta: {
					//元信息
					permission: true,
				},
			},
		],
	},
	{
		path: "/Login",
		name: "Login",
		component: Login,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
	{
		path: "/Reg",
		name: "Reg",
		component: Reg,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
	{
		path: "/List",
		name: "List",
		component: List,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
	{
		path: "/Search",
		name: "Search",
		component: Search,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
	{
		// 列表详细页
		path: "/listdetailed",
		name: "listdetailed",
		component: listdetailed,
		meta: {
			//元信息
			permission: false, //不需要拦截
		},
	},
];

const router = new VueRouter({
	mode: "history", //路由模式，默认是 hash
	routes,
});

export default router;
